package cn.iocoder.yudao.module.erp.dal.mysql.purchaseplan.purchaseengineeringdetail;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.erp.controller.admin.purchaseplan.vo.purchaseengineeringdetail.PurchaseEngineeringDetailPageReqVO;
import cn.iocoder.yudao.module.erp.dal.dataobject.purchaseplan.purchaseengineeringdetail.PurchaseEngineeringDetailDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 工程采购计划明细 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface PurchaseEngineeringDetailMapper extends BaseMapperX<PurchaseEngineeringDetailDO> {

    default PageResult<PurchaseEngineeringDetailDO> selectPage(PurchaseEngineeringDetailPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<PurchaseEngineeringDetailDO>()
                .eqIfPresent(PurchaseEngineeringDetailDO::getPlanId, reqVO.getPlanId())
                .eqIfPresent(PurchaseEngineeringDetailDO::getPurchaseType, reqVO.getPurchaseType())
                .eqIfPresent(PurchaseEngineeringDetailDO::getPurchaseContent, reqVO.getPurchaseContent())
                .eqIfPresent(PurchaseEngineeringDetailDO::getEstimatedQuantity, reqVO.getEstimatedQuantity())
                .eqIfPresent(PurchaseEngineeringDetailDO::getTotalPriceLimit, reqVO.getTotalPriceLimit())
                .eqIfPresent(PurchaseEngineeringDetailDO::getRemark, reqVO.getRemark())
                .betweenIfPresent(PurchaseEngineeringDetailDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(PurchaseEngineeringDetailDO::getId));
    }

    default void deleteByPlanId(Long planId){
        LambdaUpdateWrapper<PurchaseEngineeringDetailDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(PurchaseEngineeringDetailDO::getPlanId, planId);
        this.delete(updateWrapper);
    }

    default List<PurchaseEngineeringDetailDO> selectByPlanId(Long planId){
        LambdaQueryWrapper<PurchaseEngineeringDetailDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PurchaseEngineeringDetailDO::getPlanId, planId)
                .eq(PurchaseEngineeringDetailDO::getDeleted,0);
        return this.selectList(queryWrapper);
    }
}